# targetSpeed,speed,pos,torque
import matplotlib.pyplot as plt
import numpy as np

# 读取数据
tail  =   200
data = np.loadtxt('ss88.txt', skiprows=2, delimiter=',')
datalen=len(data)
datalen=datalen-tail
targetPos = data[:datalen, 0]
targetSpeed = data[:datalen, 1]
pos = data[:datalen, 2]
speed = data[:datalen, 3]*6
torque = data[:datalen, 4]
cmdSpeed = data[:datalen, 5]*6
# 创建图形和子图
fig, axes = plt.subplots(6, 1, figsize=(8, 10))

# 绘制目标Pos
axes[0].plot(targetPos, label='Target Pos', color='blue')
axes[0].plot(pos, label='Pos', color='red')
axes[0].set_title('Target Pos vs Pos')
axes[0].legend()
# 绘制目标速度
axes[1].plot(targetSpeed, label='Target Speed', color='blue')
axes[1].plot(speed, label='Speed', color='green')
axes[1].set_title('Target Speed')
axes[1].set_title('Target Speed vs Speed')
axes[1].legend()
# 绘制速度
axes[2].plot(pos)
axes[2].set_title('Position')
# 绘制位置
axes[3].plot(speed)
axes[3].set_title('Speed')
# 绘制扭矩
axes[4].plot(torque)
axes[4].set_title('Torque')
# 绘制速度指令
axes[5].plot(cmdSpeed)
axes[5].set_title('cmdSpeed')

# 调整子图之间的间距
plt.tight_layout()




# 创建第二个Figure和Axes对象  
fig2, ax2 = plt.subplots()  
ax2.plot(targetPos, label='targetPos', color='blue', linestyle='-')   
ax2.plot(pos, label='pos', color='red', linestyle='-')   
ax2.legend()  
ax2.set_title('Comparison_of_position')  
# 显示网格  
plt.grid(True) 
# 显示第二个图窗  
plt.show() 